<template>
  <div>
    <img src="~@/assets/logo.png" height="120px" width="300px" alt="秒杀系统"/>
  </div>
</template>

<script>
import axios from "axios";
import { getServerUrl } from "@/config/sys";

export default {
  name: "Header",
  methods: {
    refreshToken() {
      let url = getServerUrl("refreshToken");
      let token = window.sessionStorage.getItem("token");
      if (!token) {
        alert("登录信息失效，请重新登录。");
      }
      axios.defaults.headers.common['token'] = token;
      axios.get(url, {})
      .then(response => {
        if (response.data.code == 0) {
          console.log("refreshToken success");
        }
      }).catch(error => {
        alert(error + '请联系管理员。');
      })
    }
  },
  // 文档加载结束后
  mounted() {
    // 10min刷新一次token
    setInterval(this.refreshToken, 1000 * 60 * 10);
    // setInterval(this.refreshToken, 5000);
  }
}
</script>

<style scoped>

</style>
